{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcfcms.css?v={$version}"/>
</head>
<body>
<div class="layui-fluid" id="LAY-component-layer-list">
<div class="layui-card">
    <div class="layui-card-header">欢迎您使用在线升级功能</div>
    <div class="layui-card-body">
        <ul class="project" id="project">
            <li title="升级PCFCMS核心程序" id="pcfbtnupdate">
                <div class="img"><img src="{__ADMIN_PATH}/assets/images/update.png" /></div>
                <div class="txt">在线升级</div>
            </li>
            <li title="远程检测是否有升级包" id="pcfupcheck">
                <div class="img"><img src="{__ADMIN_PATH}/assets/images/alias.png" /></div>
                <div class="txt">远程检测</div>
            </li>
            <li title="配置升级服务器环境" id="pcfbtn" data-type="set" data-url="{:url('/update/set')}">
            <div class="img"><img src="{__ADMIN_PATH}/assets/images/setting.png" /></div>
            <div class="txt">环境配置</div>
            </li>
        </ul>
        <div class="pcfclear"></div>
    </div>
</div>
</div>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
		    
        // 检查是否有升级包
        $(document).on("click","#pcfupcheck",function(){
			  layer.msg('正在处理请勿刷新页面', {icon: 16,shade: 0.01,time:1000000});
    				$.ajax({
    				  type : "GET",
    				  url  : "{:url('/update/check')}",
    				  dataType : "JSON",
    				  success: function(res) {
    					  layer.closeAll();
    					  if (1 == res.code) {
      						 if(2 == res.data.code){
      							parent.layer.confirm('检测到新版本', {btn:['确定']}); 
      						 }else{
      							parent.layer.confirm('无新版本', {btn:['确定']}); 
      						 }
    					  }else{ 

                  parent.layer.confirm(res.msg, {btn:['确定']}, function(){
                      top.location.reload();
                  });

    					  }
    				  }
    				});
        });
		
		    // 在线升级
        $(document).on("click","#pcfbtnupdate",function(){
    			parent.layer.confirm('在线升级会连接远程服务器，响应较慢，请耐心等候！<br>不使用在线升级，请点“取消”', {
    			  btn: ['确定','取消'] //按钮
    			}, function(){
              $.ajax({
                    type : "POST",
                    url  : "{:url('/update/upmain')}",
                    dataType : "JSON",
                    success: function(res) {
                        layer.closeAll();
                        if (1 == res.code) {
                            parent.layer.confirm(res.msg, {btn:['确定']}, function(){
                                top.location.reload();
                            });
                        }else{
                            parent.layer.confirm(res.msg, {btn:['确定']}, function(){
                                top.location.reload();
                            });
                        }
                    }
              }); 
    			});
        });
		
        $(document).on("click","#LAY-component-layer-list #pcfbtn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });
		
        var active = {
            set: function(){
                layer.open({
                    type: 2,
                    title: '环境配置',
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: $(this).attr('data-url')
                });	
            },
        };
    });
</script>
</body>
</html>